#-*- coding:utf-8 -*-


def first_sort(l,low,high):
    flag = l[high]
    print('flag= %s'%(flag))
    while(low<high):
        while (low < high and l[low] <= flag):
            low += 1
        l[high] = l[low]
        print('l[low]= %s,%s' %(low,l))
        while (low < high and l[high] >= flag):
            high -= 1
        l[low] = l[high]
        print('l[high]= %s,%s'%(high,l))
    l[low] = flag
    print('l=%s' %l)
    return low


def quickSort(l,low,high):
    if(low < high):
        mid = first_sort(l,low,high)
        print('mid=%s' % mid)
        quickSort(l,low,mid-1)
        quickSort(l,mid+1, high)



if __name__ == '__main__':
    l = [5, 1, 3, 8, 9, 4, 7, 6]
    quickSort(l,0,len(l)-1)
    print l
